from django import http
from apps.user.models import User


def user_info_response(k, way):
    """
    :param k: 查询参数
    :param way: 查询方式
    :return: name,sex,age,phone
    """
    try:
        if way == 'phone':
            user = User.objects.get(phone=k)
        elif way == 'token':
            user = User.objects.get(token=k)
        elif way == 'id':
            user = User.objects.get(id=k)
        elif way == 'token':
            user = User.objects.get(token=k)
        name = user.name
        sex = user.sex
        age = user.age
        phone = user.phone
        data_dict = {
            'name': name,
            'sex': sex,
            'age': age,
            'phone': phone,
        }
        return {'code': 'success', 'data': data_dict}
    except Exception as e:
        return {'code': 'error', 'data': '请输入正确的查询参数'}
